package com.twobu.twobuinsight.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.twobu.twobuinsight.common.Result;
import com.twobu.twobuinsight.entity.Task;
import com.twobu.twobuinsight.service.TaskService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/task")
@Tag(name = "任务管理", description = "任务相关接口")
@Deprecated
public class TaskController {

    @Autowired
    private TaskService taskService;

    @GetMapping("/list")
    @Operation(summary = "获取任务列表")
    public Result<Page<Task>> list(@RequestParam(defaultValue = "1") Integer current,
                                  @RequestParam(defaultValue = "10") Integer size) {
        Page<Task> page = new Page<>(current, size);
        return Result.success(taskService.page(page));
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据ID获取任务")
    public Result<Task> getById(@PathVariable Long id) {
        return Result.success(taskService.getById(id));
    }

    @PostMapping
    @Operation(summary = "添加任务")
    public Result<Boolean> add(@RequestBody Task task) {
        return Result.success(taskService.save(task));
    }

    @PutMapping
    @Operation(summary = "更新任务")
    public Result<Boolean> update(@RequestBody Task task) {
        return Result.success(taskService.updateById(task));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除任务")
    public Result<Boolean> delete(@PathVariable Long id) {
        return Result.success(taskService.removeById(id));
    }
}
